//
//  OrderSquareVC.m
//  DaleTou
//
//  Created by candyxj on 2018/5/29.
//  Copyright © 2018年 geren. All rights reserved.
//

#import "OrderSquareVC.h"
#import "Appearance.h"
#import "OrderSquareCell.h"
#import <MJRefresh/MJRefresh.h>

@interface OrderSquareVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic , strong ) UITableView *tableView;
@property( nonatomic , strong ) NSMutableArray *dataSourceArr;
@property( nonatomic , strong ) NSArray *dataArray;
@property( nonatomic , strong ) NSArray *threedataArray;
@property( nonatomic , strong ) NSArray *secentdataArray;
@property(nonatomic,assign)NSInteger index;
@end

@implementation OrderSquareVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"ffffff"];
    [self setNavConfigStartColor:@"#F57321" endColor:@"#F57321"];
    [self ApptitileView:@"晒单广场"];
    _index = 0;
    self.dataSourceArr = [NSMutableArray arrayWithArray:self.dataArray];
    
    [self.view addSubview:self.tableView];
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSourceArr.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    OrderSquareCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if ( !cell) {
        
        cell = [[NSBundle mainBundle] loadNibNamed:@"OrderSquareCell" owner:nil options:nil].firstObject;
    }
    NSDictionary *dataDic = self.dataSourceArr[indexPath.section];
    cell.dataDic = dataDic;
    
    return cell;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 200;
}



-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Height, 10)];
    headerView.backgroundColor = [UIColor colorWithRed:240.0/255 green:240.0/255 blue:240.0/255 alpha:1.0];
    return headerView;
}


-(CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if ( section == 0) {
        
        return 0.01;
    }else{
        
        return 5;
    }
}


-(void)loadData{
    _index = 0;
    [self.tableView.mj_header endRefreshing];
    self.dataSourceArr = [NSMutableArray arrayWithArray:self.dataArray];
    [self.tableView reloadData];
}


-(void)loadMoreData{
    
    [self.tableView.mj_footer endRefreshing];
    if (_index==0) {
           self.dataSourceArr = [NSMutableArray arrayWithArray:[self.dataSourceArr arrayByAddingObjectsFromArray:self.secentdataArray]];
        _index ++;
    }else if(_index ==2){
          self.dataSourceArr = [NSMutableArray arrayWithArray:[self.dataSourceArr arrayByAddingObjectsFromArray:self.threedataArray]];
           _index ++;
    }else{
           _index ++;
    }

    [self.tableView reloadData];
}









#pragma mark setter/getter
-(UITableView *)tableView{
    
    if ( !_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, Main_Screen_Width, Main_Screen_Height - NAVIGATION_BAR_HEIGHT)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        //        _tableView.tableHeaderView = self.headerView;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            
            [self loadData];
        }];
        
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            
            [self loadMoreData];
        }];
    }
    return _tableView;
}



-(NSMutableArray *)dataSourceArr{
    
    if ( !_dataSourceArr) {
        
        _dataSourceArr = [NSMutableArray array];
    }
    return _dataSourceArr;
}



-(NSArray *)dataArray{
    
    if ( !_dataArray) {
        _dataArray = @[
                       @{@"userIconImage":@"1",@"name":@"一路有你",@"date":@"今天 11:18",@"num":@"大乐透 第2018053期",@"money":@"12",@"moneyPercent":@"101",@"getMoney":@"1200.00"},
                       @{@"userIconImage":@"22",@"name":@"旧爱装",@"date":@"昨天 10:18",@"num":@"大乐透 第2018052期",@"money":@"24",@"moneyPercent":@"20",@"getMoney":@"500.00"},
                       @{@"userIconImage":@"33",@"name":@"期待你的爱",@"date":@"两天前 12:18",@"num":@"大乐透 第2018051期",@"money":@"61",@"moneyPercent":@"205",@"getMoney":@"234.00"},
                       @{@"userIconImage":@"44",@"name":@"毛衣",@"date":@"三天前 13:18",@"num":@"大乐透 第2018050期",@"money":@"18",@"moneyPercent":@"53",@"getMoney":@"125.00"},
                       @{@"userIconImage":@"25",@"name":@"master",@"date":@"四天前 14:18",@"num":@"大乐透 第2018049期",@"money":@"12",@"moneyPercent":@"25",@"getMoney":@"357.00"},
                       @{@"userIconImage":@"46",@"name":@"圣骑士",@"date":@"五天前 15:18",@"num":@"大乐透 第2018048期",@"money":@"2",@"moneyPercent":@"1000",@"getMoney":@"763.00"},
                       @{@"userIconImage":@"23",@"name":@"神斗士",@"date":@"六天前 13:18",@"num":@"大乐透 第2018047期",@"money":@"100",@"moneyPercent":@"90",@"getMoney":@"1234.00"},
                       @{@"userIconImage":@"24",@"name":@"user",@"date":@"一周前 14:18",@"num":@"大乐透 第2018046期",@"money":@"97",@"moneyPercent":@"86",@"getMoney":@"3763.00"},
                       @{@"userIconImage":@"28",@"name":@"admin",@"date":@"一周前 15:18",@"num":@"大乐透 第2018045期",@"money":@"35",@"moneyPercent":@"29",@"getMoney":@"285.00"},
                               ];
    }
    return _dataArray;
}


-(NSArray *)secentdataArray{
    
    if ( !_secentdataArray) {
        _secentdataArray = @[
                       @{@"userIconImage":@"1",@"name":@"还好有你",@"date":@"今天 11:18",@"num":@"大乐透 第2018053期",@"money":@"12",@"moneyPercent":@"101",@"getMoney":@"1200.00"},
                       @{@"userIconImage":@"22",@"name":@"爱不完",@"date":@"昨天 10:18",@"num":@"大乐透 第2018052期",@"money":@"24",@"moneyPercent":@"20",@"getMoney":@"500.00"},
                       @{@"userIconImage":@"33",@"name":@"丁小布丁",@"date":@"两天前 12:18",@"num":@"大乐透 第2018051期",@"money":@"61",@"moneyPercent":@"205",@"getMoney":@"234.00"},
                       @{@"userIconImage":@"44",@"name":@"独身",@"date":@"三天前 13:18",@"num":@"大乐透 第2018050期",@"money":@"18",@"moneyPercent":@"53",@"getMoney":@"125.00"},
                       @{@"userIconImage":@"25",@"name":@"阿波罗",@"date":@"四天前 14:18",@"num":@"大乐透 第2018049期",@"money":@"12",@"moneyPercent":@"25",@"getMoney":@"357.00"},
                       @{@"userIconImage":@"46",@"name":@"天启",@"date":@"五天前 15:18",@"num":@"大乐透 第2018048期",@"money":@"2",@"moneyPercent":@"1000",@"getMoney":@"763.00"},
                       @{@"userIconImage":@"23",@"name":@"新月",@"date":@"六天前 13:18",@"num":@"大乐透 第2018047期",@"money":@"100",@"moneyPercent":@"90",@"getMoney":@"1234.00"},
                       @{@"userIconImage":@"24",@"name":@"阿斗",@"date":@"一周前 14:18",@"num":@"大乐透 第2018046期",@"money":@"97",@"moneyPercent":@"86",@"getMoney":@"3763.00"},
                       @{@"userIconImage":@"28",@"name":@"白菜",@"date":@"一周前 15:18",@"num":@"大乐透 第2018045期",@"money":@"35",@"moneyPercent":@"29",@"getMoney":@"285.00"},
                       ];
    }
    return _secentdataArray;
}


-(NSArray *)threedataArray{
    
    if ( !_threedataArray) {
        _threedataArray = @[
                       @{@"userIconImage":@"1",@"name":@"张天使",@"date":@"今天 11:18",@"num":@"大乐透 第2018053期",@"money":@"12",@"moneyPercent":@"101",@"getMoney":@"1200.00"},
                       @{@"userIconImage":@"22",@"name":@"徐思",@"date":@"昨天 10:18",@"num":@"大乐透 第2018052期",@"money":@"24",@"moneyPercent":@"20",@"getMoney":@"500.00"},
                       @{@"userIconImage":@"33",@"name":@"宝儿姐",@"date":@"两天前 12:18",@"num":@"大乐透 第2018051期",@"money":@"61",@"moneyPercent":@"205",@"getMoney":@"234.00"},
                       @{@"userIconImage":@"44",@"name":@"气体源流",@"date":@"三天前 13:18",@"num":@"大乐透 第2018050期",@"money":@"18",@"moneyPercent":@"53",@"getMoney":@"125.00"},
                       @{@"userIconImage":@"25",@"name":@"ithsA",@"date":@"四天前 14:18",@"num":@"大乐透 第2018049期",@"money":@"12",@"moneyPercent":@"25",@"getMoney":@"357.00"},
                       @{@"userIconImage":@"46",@"name":@"mamamiya",@"date":@"五天前 15:18",@"num":@"大乐透 第2018048期",@"money":@"2",@"moneyPercent":@"1000",@"getMoney":@"763.00"},
                       @{@"userIconImage":@"23",@"name":@"甜豆",@"date":@"六天前 13:18",@"num":@"大乐透 第2018047期",@"money":@"100",@"moneyPercent":@"90",@"getMoney":@"1234.00"},
                       @{@"userIconImage":@"24",@"name":@"唐山",@"date":@"一周前 14:18",@"num":@"大乐透 第2018046期",@"money":@"97",@"moneyPercent":@"86",@"getMoney":@"3763.00"},
                       @{@"userIconImage":@"28",@"name":@"哟哟哒",@"date":@"一周前 15:18",@"num":@"大乐透 第2018045期",@"money":@"35",@"moneyPercent":@"29",@"getMoney":@"285.00"},
                       ];
    }
    return _threedataArray;
}

//-(NSMutableArray *)dataSourceArr{
//
//    if ( !_dataSourceArr) {
//        _dataSourceArr = [NSMutableArray arrayWithArray:@[
//        @{@"userIconImage":@"1",@"name":@"一路有你",@"date":@"18-05-29 11:18",@"num":@"大乐透 第2018053期",@"money":@"12",@"moneyPercent":@"101",@"getMoney":@"1200.00"},
//        @{@"userIconImage":@"22",@"name":@"旧爱装",@"date":@"18-05-28 10:18",@"num":@"大乐透 第2018052期",@"money":@"24",@"moneyPercent":@"20",@"getMoney":@"500.00"},
//        @{@"userIconImage":@"33",@"name":@"期待你的爱",@"date":@"18-05-27 12:18",@"num":@"大乐透 第2018051期",@"money":@"61",@"moneyPercent":@"205",@"getMoney":@"234.00"},
//        @{@"userIconImage":@"44",@"name":@"毛衣",@"date":@"18-05-26 13:18",@"num":@"大乐透 第2018050期",@"money":@"18",@"moneyPercent":@"53",@"getMoney":@"125.00"},
//        @{@"userIconImage":@"25",@"name":@"master",@"date":@"18-05-25 14:18",@"num":@"大乐透 第2018049期",@"money":@"12",@"moneyPercent":@"25",@"getMoney":@"357.00"},
//        @{@"userIconImage":@"46",@"name":@"圣骑士",@"date":@"18-05-24 15:18",@"num":@"大乐透 第2018048期",@"money":@"2",@"moneyPercent":@"1000",@"getMoney":@"763.00"},
//                                                          ]];
//    }
//    return _dataSourceArr;
//}


@end





